<?php

$username=$_POST['username'];
$password=$_POST['password'];

$dbhost = 'localhost';  // mysql服务器主机地址
$dbuser = 'root';            // mysql用户名
$dbpass = 'root';          // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass,'login');
if(! $conn )
{
    die('连接失败: ' . mysqli_error($conn));
}

if(!($username&& $password)){
	echo"<script>alert('输入的账号或密码为空！请重新输入账号和密码');</script>";
}
else{
$sql = "SELECT *
        FROM login
        where (username='$username') and (password='$password')";

$result = mysqli_query( $conn, $sql );

if($result->num_rows ==0)
{
    die('密码或用户名错误: ' . mysqli_error($conn));
}

header('location:message.html');

mysqli_close($conn);
}


/*
while($row = mysqli_fetch_array($result)){   //输出result
    echo "<tr>";
    echo "<td>".$row['username']."</td>" ;
    echo "<td>".$row['password']."</td>" ;
    echo "<tr>";
    }

echo $password;//输出输入的密码
*/
/*
$sql = "SELECT username,password
        FROM login
        where username='$username'";

$result = mysqli_query( $conn, $sql );

$row = mysqli_fetch_array($result)

if($row["password"]!=$password)
{
    die('密码或用户名错误: ' . mysqli_error($conn));
}
else {
echo '<h2>登录成功</h2>';
}
echo '</table>';
mysqli_close($conn);
*/

?>